/*
* Copyright (c) 2010-2011 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description: Camerality viewfinder.
*
*/

#ifndef CAMERALITYVIEWFINDER_H_
#define CAMERALITYVIEWFINDER_H_

#include <ecam.h>
#include <videorecorder.h>

class MCameralityViewfinderObserver;

/*!
* CCameralityViewfinder class
*/
class CCameralityViewfinder :
    public CBase,
    public MCameraObserver2,
    public MVideoRecorderUtilityObserver
{
public:
    enum TViewfinderState
        {
        EIdle,
        EReady,
        ERunning
        };

    enum TAspectRatio
        {
        ERatio4by3,
        ERatio16by9,
        ERatio11by9
        };

public: // Public constructor and destructor
    static CCameralityViewfinder *NewL();
    virtual ~CCameralityViewfinder();

public: // From MCameraObserver2
    virtual void HandleEvent(const TECAMEvent& aEvent);
    virtual void ViewFinderReady(MCameraBuffer& aCameraBuffer, TInt aError);
    virtual void ImageBufferReady(MCameraBuffer& aCameraBuffer, TInt aError);
    virtual void VideoBufferReady(MCameraBuffer& aCameraBuffer, TInt aError);

public: // From MVideoRecorderUtilityObserver
    virtual void MvruoOpenComplete(TInt aError);
    virtual void MvruoPrepareComplete(TInt aError);
    virtual void MvruoRecordComplete(TInt aError);
    virtual void MvruoEvent(const TMMFEvent& aEvent);

public: // New methods
    void SetObserver(MCameralityViewfinderObserver* aObserver);
    TViewfinderState State() const;
    void Start(RWindowBase& aWindow, TRect& aRect);
    void Stop();
    void Release();

private:
    void SetState(TViewfinderState aState);
    TBool CheckError(TInt aError);

    void Initialize();
    void HintUseCase();
    void Open();
    void Prepare();
    void StartNow();

    void FindControllerL(TUid& controllerId,
                          TUid& formatId);

    static TAspectRatio AspectRatio(const TSize& size);

private:
    CCameralityViewfinder();
    void ConstructL();

private:
    CCamera* iCamera;
    CVideoRecorderUtility* iVideoRecorder;

    MCameralityViewfinderObserver* iObserver;

    RWindowBase* iWindow;
    TRect iRect;
    TViewfinderState iState;
};


class MCameralityViewfinderObserver
{
public:
    virtual void ViewfinderStateChanged(
            CCameralityViewfinder::TViewfinderState oldState,
            CCameralityViewfinder::TViewfinderState newState) = 0;
    virtual void ViewfinderError(TInt error) = 0;
};

#endif /* CAMERALITYVIEWFINDER_H_ */

// end of file
